﻿package tg.app.rj.workorder;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import psdi.app.workorder.WORemote;
import psdi.common.action.ActionCustomClass;
import psdi.mbo.Mbo;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.server.MXServer;
import psdi.util.MXApplicationException;
import psdi.util.MXException;


//
//	流程节点操作：检修汇报的正向操作
//
public class WO_BZHB implements ActionCustomClass {

	public void applyCustomAction(MboRemote mboremote, Object[] aobj)
			throws MXException, RemoteException {
		WORemote womboremote = (WORemote) mboremote;
		String status = womboremote.getString("status");
		String user = womboremote.getUserInfo().getPersonId();
		Date date = MXServer.getMXServer().getDate();
		// String worktype = womboremote.getString("WORKTYPE");// 菜单类型
		// if (worktype.equals("CM")) {
		WOCM(womboremote, date, status, user);
	}

	protected void WOCM(WORemote womboremote, Date date, String status,
			String user) throws MXException, RemoteException {
		// if (checkRYGS(womboremote, date, womboremote.getString("wonum"))
		// .equals("yes")) {
		// throw new MXApplicationException("workorder", "RYGS");// 人员工时
		// }
		if (womboremote.getString("WO16").equals("")
				|| womboremote.getString("WO17").equals("")
				|| womboremote.getString("WO18").equals("")
				|| womboremote.getString("WO19").equals("")
				|| womboremote.getString("ACTSTART").equals("")
				|| womboremote.getString("ACTFINISH").equals("")) {
			throw new MXApplicationException("workorder", "BZHBERROR");// 必须填写检修汇报相关内容！
		}

		womboremote.changeStatus("APPR1", date, "工作流更改状态为APPR1", 2L);
		womboremote.setValue("wo30", womboremote.getUserInfo().getPersonId(),
				11L);
		womboremote.setValue("wo31", date, 11L);
	}
	// MboSetRemote mbosetremote = womboremote
	// .getMboSet("SHOWACTUALLABOR");
	// MboRemote mboremote1 = mbosetremote.getMbo(0);
	// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	// SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm:ss");
	// SimpleDateFormat sdf2 = new
	// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	// String hbsjf = sdf2.format(date);
	// try {
	// if ((!(mboremote1.isNull("finishdate")))
	// && (!(mboremote1.isNull("finishtime")))) {
	// String sjrq = sdf.format(mboremote1.getDate("finishdate"));//
	// 实际日期
	// String sjsj = sdf1.format(mboremote1.getDate("finishtime"));//
	// 实际时间
	// String sjrqsj = sjrq + " " + sjsj;
	// Date sjdate = sdf2.parse(sjrqsj);
	// Date hbdate = sdf2.parse(hbsjf);
	// if ((mboremote1.getBoolean("WFACTIVE"))
	// && (sjdate.after(hbdate)))
	// throw new MXApplicationException("workorder",
	// "YGSJSJ>BZHBSJ");// 员工的实际完成时间不能大于班组完成工作的汇报时间！
	// }

	// } catch (RemoteException remoteexception) {
	// remoteexception.getMessage();
	// }
	// }
	//
	// protected String checkRYGS(MboRemote mboremote, Date date, String
	// wonum)
	// throws MXException, RemoteException {
	// Mbo mbo = (Mbo) mboremote.getThisMboSet().getMbo();
	// Statement statement = null;
	// ResultSet resultset = null;
	// String countNum = "no";
	// try {
	// Connection connection = mbo.getMboServer().getDBConnection(
	// mbo.getUserInfo().getConnectionKey());
	// String s6 = "select COUNT (*) from labtrans where refwo='" + wonum
	// + "'";
	// statement = connection.createStatement();
	// resultset = statement.executeQuery(s6);
	//
	// if (resultset.next()) {
	// if (!(resultset.getString(1).equals("0"))) {
	// countNum = "yes";
	// }
	// }
	// } catch (Exception exception) {
	// exception.printStackTrace();
	// try {
	// if (resultset != null) {
	// resultset.close();
	// }
	//
	// } catch (SQLException localSQLException) {
	// }
	//
	// } finally {
	// try {
	// resultset.close();
	// statement.close();
	// } catch (SQLException e) {
	// e.printStackTrace();
	// }
	// mbo.getMboServer().freeDBConnection(
	// mbo.getUserInfo().getConnectionKey());
	// }
	// return countNum;
	// }

}
